//package com.lysj.bhp.scheduled.job;
//
//
//import com.lysj.bhp.scheduled.base.ScheduledContent;
//import com.lysj.bhp.scheduled.domain.BhpcWallet;
//import com.lysj.bhp.scheduled.domain.Dividend;
//import com.lysj.bhp.scheduled.domain.User;
//import com.lysj.bhp.util.random.FormatUtil;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import java.math.BigDecimal;
//import java.util.Date;
//import java.util.List;
//import java.util.Map;
//
//@Component
//public class DividendJob extends ScheduledContent {
//
//    private static Logger logger = LoggerFactory.getLogger(DividendJob.class);
//
//
//    @Scheduled(cron = "00 15 01 * * ?")
//    public void createDividends() {
//
//        Map<String, String> map = exchangeRateService.rates();
//        if (null == map || map.isEmpty()) {
//            return;
//        }
//        BigDecimal btcToDollar = new BigDecimal(map.get("btcToDollar"));
//        BigDecimal bhpcToDallar = new BigDecimal(map.get("bhpcToDallar"));
//        BigDecimal ethToDollar = new BigDecimal(map.get("ethToDollar"));
//
//        List<BhpcWallet> bhpcWallets = bhpcWalletRepository.findByAvailBalanceGreaterThan(new BigDecimal("300"));
//
//        bhpcWallets.forEach(bhpcWallet -> {
//            //获取钱包对应的用户
//            User user = userRepository.findOne(bhpcWallet.getUserId());
//
////            BigDecimal btcDividend = bhpcWallet.getAvailBalance().multiply(bhpcToDallar).multiply(new BigDecimal("0.12" )).divide(new BigDecimal("365" ),18,BigDecimal.ROUND_DOWN).divide(btcToDollar,8,BigDecimal.ROUND_DOWN);
//
//            BigDecimal ethDividend = bhpcWallet.getAvailBalance().multiply(bhpcToDallar).multiply(new BigDecimal("0.08")).divide(new BigDecimal("365"), 18, BigDecimal.ROUND_DOWN).divide(ethToDollar, 8, BigDecimal.ROUND_DOWN);
//
//            logger.info(user.getUserId() + ":" + bhpcWallet.getAvailBalance() + "=>" + ethDividend);
//
////            user.setBtcDividend(user.getBtcDividend().add(btcDividend)); //生成的利息添加到,用户表新增的比特币分红字段中
//
//            user.setDividend(user.getDividend().add(ethDividend));
//
//            Dividend dividendQuery = dividendRepository.findTopByOrderByDividentIdDesc();
//            long nextId = 1L;
//            if (dividendQuery != null) {
//                nextId = dividendQuery.getDividentId() + 1;
//            }
//            Dividend dividendCreate = new Dividend();
//            dividendCreate.setDividentId(nextId);
//            dividendCreate.setUserId(user.getUserId());
//            dividendCreate.setEmail(user.getEmail());
//            dividendCreate.setBhpc(bhpcWallet.getAvailBalance());
//
////            dividendCreate.setBtcDividend(btcDividend);  //以比特币为单位的利息
//
//            dividendCreate.setDividend(ethDividend);  //以太坊为单位的利息
//
//            dividendCreate.setCurrentBitcoinToDollar(btcToDollar);
//            dividendCreate.setCurrentEthereumToDollar(ethToDollar);
//            dividendCreate.setCurrentBhpcToDollar(bhpcToDallar);
//            dividendCreate.setCreateTime(new Date());
//
//            userRepository.save(user);
//            dividendRepository.save(dividendCreate);
//        });
//    }
//
////    @Scheduled(cron = "00 57 14 * * ?")
////    public void editDividends() throws Exception {
////        List<Dividend> dividends = dividendRepository.findByCreateTimeAfter(FormatUtil.stringTodate2("2018-09-18"));
////        dividends.forEach(dividend -> {
////            BigDecimal errorDividend = dividend.getDividend();
////            System.out.println("errorDividend:" + errorDividend);
////            BigDecimal rightDividend = errorDividend.multiply(new BigDecimal(0.1)).setScale(8, BigDecimal.ROUND_DOWN);
////            dividend.setDividend(rightDividend);
////            System.out.println("rightDividend:" + rightDividend);
////
////
////
////            BigDecimal moreDividend = errorDividend.subtract(rightDividend);
////            System.out.println("moreDividend:" + moreDividend);
////            User user = userRepository.findOne(dividend.getUserId());
////            System.out.println("userErrorDividend:" + user.getDividend());
////            user.setDividend(user.getDividend().subtract(moreDividend));
////            System.out.println("userRightDividend:" + user.getDividend());
////
////            dividendRepository.save(dividend);
////            userRepository.save(user);
////        });
//
////    }
//
//
//}
